package demo.generic;

import java.util.Random;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2020/7/7-2020
 * @Description: 定义泛型接口的实现类
 */
public class RobotFactory implements GenericIFactory<Integer,String> {
    private String[] stringRobot=new String[]{"Hello","Hi"};
    private Integer[] integerRobot=new Integer[]{111,000};
    @Override
    public Integer nextObject() {
        Random random = new Random();
        //[0,2) 表示从0的闭区间到2的开区间取随机数
        int i = random.nextInt(2);
        return integerRobot[i];
    }

    @Override
    public String nextNumber() {
        Random random = new Random();
        //[0,2) 表示从0的闭区间到2的开区间取随机数
        int i = random.nextInt(2);
        return stringRobot[i];
    }

    public static void main(String[] args) {
        GenericIFactory<Integer,String> genericIFactory = new RobotFactory();
        String str = genericIFactory.nextNumber();
        Integer obj= genericIFactory.nextObject();
        System.out.println("nextNumber=="+str+"\n nextObject=="+obj);
    }
}
